<?php
namespace app\index\controller;

use app\index\logic\UserLogic;
use EasyWeChat\Foundation\Application;
use think\Controller;
use think\Request;

class Base extends Controller
{

    /**
     * @var Application
     */
    protected $wechat;
    protected $is_debug;
    public function __construct(Request $request = null)
    {
        $this->is_debug = false;
        $this->wechat = new Application(get_wechat_config());
        $logic = new UserLogic();
        $result = $logic->check_user();
        if($result == false || $result['update_time'] + 60*60 < time()){//5分钟更新一次用户信息
            $back_url = 'http://'.$_SERVER['HTTP_HOST'].'/index/wechat/oauth_call_back';
            $response = $this->wechat->oauth->scopes(['snsapi_userinfo'])->redirect($back_url);
            $response->send();
        }
        parent::__construct($request);
        $wechat = new Application(get_js_wechat_config());
        $js = $wechat->js->config(['getLocation','openLocation','scanQRCode']);
        $this->assign('wechat',$js);
        $this->assign('version','v5.6');
    }
}
